package crp.core.analysis.domain.services;

import crp.core.analysis.domain.models.ViewFlowEntity;
import crp.core.analysis.domain.repositories.ViewFlowRepository;
import crp.core.course.domain.models.CourseEntity;
import crp.core.shared.cache.CacheNames;
import io.quarkus.cache.CacheResult;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.List;
import java.util.Optional;

@ApplicationScoped
public class ViewFlowSearcher {
    private final ViewFlowRepository viewFlowRepository;

    @Inject
    public ViewFlowSearcher(ViewFlowRepository viewFlowRepository) {
        this.viewFlowRepository = viewFlowRepository;
    }

    public Optional<ViewFlowEntity> byId(String id) {
        return viewFlowRepository.findByIdOptional(id);
    }

    @CacheResult(cacheName = CacheNames.COURSES_TOP_VIEWS)
    public List<CourseEntity> topViewsPublicCourses(Integer limit) {
        return viewFlowRepository.topViewsPublicCourseIds(limit);
    }
}
